function Y = caffe_batch(X, net_file, net_model, solver_mode, phase, batch_size)

%%
net_file = srdata.checkFileFormat(net_file, '.prototxt');
net_model = srdata.checkFileFormat(net_model, '.caffemodel');

%%
% batch_size = 300;
[w, h, c, N] = size(X);
% Y = zeros(w, h, c, N);
pp = 0;
mycaffe.init(solver_mode);
bach_num = ceil(N / batch_size);
for b = 1 : bach_num
    fprintf('%d/%d ', b, bach_num);
    pp = pp(end)+1 : pp(end)+batch_size;
    
    if pp(end) > N
        pp = pp(1) : N;
    end
    Xpp = X(:, :, :, pp);
    
    net = caffe.Net(net_file, net_model, phase);
    net.blobs('data').reshape([w, h, c, length(pp)]);
    net.reshape();
    net.forward({Xpp});
    y = single(net.blobs(net.outputs{1}).get_data());
    if b == 1
        [w, h, c, ~] = size(y);
        Y = zeros(w, h, c, N);
    end
    Y(:, :, :, pp) = y;
    mycaffe.reset_all();
end
